﻿using System.Data.Entity;
using EntityFramework6.Services.CustomConventions;

namespace EntityFramework6.Services.Data
{
    // Separate class for overriding the model configurations
    public partial class BookContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Code that maps the book to stored procedure with custom names!!
            modelBuilder.Entity<Book>().MapToStoredProcedures(s=> 
                s.Update(u=> u.HasName("usp_UpdateBook")).
                Insert(i=> i.HasName("usp_InsertBook")).
                Delete(d=> d.HasName("usp-DeleteBook")));

            // decimal convention (custom convention)
            modelBuilder.Conventions.Add(new DecimalConvention());

            base.OnModelCreating(modelBuilder);
        }
    }
}
